package tech.lq0.dreamaticvoyage.network.packet;

import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.network.NetworkEvent;
import tech.lq0.dreamaticvoyage.network.ClientPacketHandler;

import java.util.function.Supplier;

public record FukamizuFermenterSyncPacket(BlockPos pos, FluidStack inputStack, FluidStack outputStack) {

    public static void encode(FukamizuFermenterSyncPacket packet, FriendlyByteBuf buf) {
        buf.writeBlockPos(packet.pos);
        buf.writeFluidStack(packet.inputStack);
        buf.writeFluidStack(packet.outputStack);
    }

    public static FukamizuFermenterSyncPacket decode(FriendlyByteBuf buf) {
        return new FukamizuFermenterSyncPacket(buf.readBlockPos(), buf.readFluidStack(), buf.readFluidStack());
    }

    public static void handle(FukamizuFermenterSyncPacket message, Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
                () -> () -> ClientPacketHandler.handleFukamizuFermenterSyncPacket(message, ctx)));
        ctx.get().setPacketHandled(true);
    }
}
